package finalfinancialanalyst.business;

import java.io.Serializable;
import java.math.BigDecimal;
import java.math.RoundingMode;

public final class Money implements Serializable {
    
        private static final long serialVersionUID = 1L;
 
	private final BigDecimal amount;
	 
	private final Currency currency;
	 
	public Money(String amount, Currency currency) {
            this.amount =  BigDecimal.valueOf(Double.parseDouble(amount));
            this.currency = currency; 
	}
	 
	public Money convertTo(Currency newCurrency) {
            //BigDecimal usdValue = ;
            BigDecimal newamount = amount.multiply(currency.getUsdValue()).divide(newCurrency.getUsdValue(),2,RoundingMode.HALF_UP);
            return new Money(newamount.toString(),newCurrency);
	}
	 
	public BigDecimal getAmount() {
		return amount;
	}
        
        public Currency getCurrency() {
            return currency;
        }
	 
}
 
